import { alarmApi } from '@/api'
import type { WorkOrderFull } from '@/types'

/**
 * @mixin 工单信息
 */
export function useWorkOrder() {
  const [order, setOrder] = useShallowState<
    Partial<WorkOrderFull>
  >({})

  const checkedUsers = computed(() => {
    return order.value.warningWorkOrderUserList
  })

  async function getOrderInfo(workOrderNum: string) {
    try {
      const { data } = await alarmApi.selectWarningAuditingByWorkOrderNum(
        workOrderNum,
      )
      setOrder(data || {})
    }
    catch (e) {}
  }

  return {
    order,
    checkedUsers,
    setOrder,
    getOrderInfo,
  }
}
